package com.edu.exam.enums;

/**
 * 成绩导出权限类型枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum GradeExportPermissionType {
    /** 只读权限 */
    READ("READ", "只读权限"),
    /** 读写权限 */
    WRITE("WRITE", "读写权限"),
    /** 管理权限 */
    ADMIN("ADMIN", "管理权限"),
    /** 审核权限 */
    REVIEW("REVIEW", "审核权限"),
    /** 导出权限 */
    EXPORT("EXPORT", "导出权限"),
    /** 打印权限 */
    PRINT("PRINT", "打印权限"),
    /** 分享权限 */
    SHARE("SHARE", "分享权限"),
    /** 完全权限 */
    FULL("FULL", "完全权限");

    private final String code;
    private final String description;

    GradeExportPermissionType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static GradeExportPermissionType fromCode(String code) {
        if (code == null) {
            throw new IllegalArgumentException("Code cannot be null");
        }
        for (GradeExportPermissionType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown code: " + code);
    }

    public static GradeExportPermissionType fromDescription(String description) {
        if (description == null) {
            throw new IllegalArgumentException("Description cannot be null");
        }
        for (GradeExportPermissionType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}